//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package rent.hj.videoplayer.subTitle.autodetect;

public class nsEUCSampler {
    int mTotal = 0;
    int mThreshold = 200;
    int mState = 0;
    public int[] mFirstByteCnt = new int[94];
    public int[] mSecondByteCnt = new int[94];
    public float[] mFirstByteFreq = new float[94];
    public float[] mSecondByteFreq = new float[94];

    public nsEUCSampler() {
        this.Reset();
    }

    public void Reset() {
        this.mTotal = 0;
        this.mState = 0;

        for(int i = 0; i < 94; ++i) {
            this.mFirstByteCnt[i] = this.mSecondByteCnt[i] = 0;
        }

    }

    boolean EnoughData() {
        return this.mTotal > this.mThreshold;
    }

    boolean GetSomeData() {
        return this.mTotal > 1;
    }

    boolean Sample(byte[] aIn, int aLen) {
        if(this.mState == 1) {
            return false;
        } else {
            int p = 0;

            for(int i = 0; i < aLen && 1 != this.mState; ++p) {
                switch(this.mState) {
                    case 0:
                        if((aIn[p] & 128) != 0) {
                            if(255 != (255 & aIn[p]) && 161 <= (255 & aIn[p])) {
                                ++this.mTotal;
                                ++this.mFirstByteCnt[(255 & aIn[p]) - 161];
                                this.mState = 2;
                            } else {
                                this.mState = 1;
                            }
                        }
                    case 1:
                        break;
                    case 2:
                        if((aIn[p] & 128) != 0) {
                            if(255 != (255 & aIn[p]) && 161 <= (255 & aIn[p])) {
                                ++this.mTotal;
                                ++this.mSecondByteCnt[(255 & aIn[p]) - 161];
                                this.mState = 0;
                            } else {
                                this.mState = 1;
                            }
                        } else {
                            this.mState = 1;
                        }
                        break;
                    default:
                        this.mState = 1;
                }

                ++i;
            }

            return 1 != this.mState;
        }
    }

    void CalFreq() {
        for(int i = 0; i < 94; ++i) {
            this.mFirstByteFreq[i] = (float)this.mFirstByteCnt[i] / (float)this.mTotal;
            this.mSecondByteFreq[i] = (float)this.mSecondByteCnt[i] / (float)this.mTotal;
        }

    }

    float GetScore(float[] aFirstByteFreq, float aFirstByteWeight, float[] aSecondByteFreq, float aSecondByteWeight) {
        return aFirstByteWeight * this.GetScore(aFirstByteFreq, this.mFirstByteFreq) + aSecondByteWeight * this.GetScore(aSecondByteFreq, this.mSecondByteFreq);
    }

    float GetScore(float[] array1, float[] array2) {
        float sum = 0.0F;

        for(int i = 0; i < 94; ++i) {
            float s = array1[i] - array2[i];
            sum += s * s;
        }

        return (float)Math.sqrt((double)sum) / 94.0F;
    }
}
